const express =require('express');
const noteModel = require('../db/model/noteModel');
const router = express.Router();
const verifyLogin = require('../middlewares/verifylogin');


// 提交数据路由
router.post('/addnote',(req,res)=>{
    noteModel.create(req.body,(err,data)=>{
        res.render('jump.html',{name:"添加成功"});
    });
})

router.get('/delnote/:id',verifyLogin,(req,res)=>{
    let {id} = req.params;
    noteModel.deleteOne({_id:id},(err,data)=>{
        if(err)return;
        res.render('jump.html',{name:"删除成功"});
        // if(err){

        // }else{
        //     // res.send('删除成功');
        //     res.render('jump.html',{name:"删除成功"});
        // }
    })
})

router.post('/update',(req,res)=>{
    let {title,content,id} = req.body;
    noteModel.updateOne({_id:id},{
        title,
        content
    },(err,data)=>{
        // res.send('修改成功');
        res.render('jump.html',{name:"修改成功"});
    })
});

module.exports = router;